﻿using AutoMapper.Internal.Mappers;
using Mes.Pendant.Common;
using Mes.Pendant.UnitMeasures;
using Mes.Pendant.Warehousesettings.Dto;
using Mes.Pendant.WarehousesettingServicess;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using System;

namespace Mes.Pendant.Web.Controllers
{
    public class WarehousesettingController : Controller
    {

		private readonly IWarehousesettings warehousesettings;

		public WarehousesettingController(IWarehousesettings warehousesettings)
		{
			this.warehousesettings = warehousesettings;
		}

		/// <summary>
		/// 仓库显示视图
		/// </summary>
		/// <returns></returns>
		public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 新增视图
        /// </summary>
        /// <returns></returns>
        public IActionResult Add()
        {
            return View();
        }

        /// <summary>
        /// 编辑视图
        /// </summary>
        /// <returns></returns>
        public IActionResult Upd(int id = 0)
        {
            ViewBag.Id = id;
            return View();
        }

        /// <summary>
        /// 显示查询分页
        /// </summary>
        /// <param name="codes"></param>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<JsonResult> WarehousesettingLists(string? codes, string? name, int page, int limit)
        {
            var ware=await warehousesettings.WarehousesettingList(codes, name, page, limit);
            return Json(new { code = 0, msg = "success", count = ware.CurrentPage, data = ware.Queryable });
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="warehousesettingDto"></param>
        /// <returns></returns>
        public async Task<int> CreateWarehousesetting(WarehousesettingDto warehousesettingDto)
        {
           var ware=await warehousesettings.CreateWarehousesetting(warehousesettingDto);
            return ware;
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="warehousesettingDto"></param>
        /// <returns></returns>
        public async Task<int> UpdateWarehousesetting(WarehousesettingDto warehousesettingDto)
        {
            var ware=await warehousesettings.UpdateWarehousesetting(warehousesettingDto);
            return ware;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DeleteWarehousesetting(int id)
        {
            var ware=await warehousesettings.DeleteWarehousesetting(id);
            return ware;
        }

        /// <summary>
        /// 根据id查询列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<WarehousesettingDto> GetWarehousesettingById(int id)
        {
            var ware =await warehousesettings.GetWarehousesettingById(id);
            return ware;
        }
    }
}
